﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DataLayer.Entities;
using NHibernate.Criterion;

namespace DataLayer.Implementations
{
    public class DonutApplication : GeneralApplication<Donut>
    {
        public IList<Donut> GetActiveDonuts()
        {
            List<ICriterion> conditions = new List<ICriterion>();
            conditions.Add(Restrictions.Eq("IsActive", true));

            return model.GetByCriterion<Donut>(conditions);
        }

        public Donut GetByDonutUniqueName(string name)
        {
            List<ICriterion> conditions = new List<ICriterion>();
            conditions.Add(Restrictions.Eq("UniqueName", name));

            return model.GetByCriterion<Donut>(conditions).FirstOrDefault();
        }

        public void Save(Donut donut)
        {
            if (donut.DonutId == null)
            {
                Save(donut, 0);
            }
            else
            {
                Save(donut, donut.DonutId.Value);
            }
        }
    }
}
